//
//  PerHeaderView.m
//  operativeSide-2.0
//
//  Created by 马腾飞 on 16/12/19.
//  Copyright © 2016年 王春程. All rights reserved.
//

#import "PerHeaderView.h"
#import <Masonry/Masonry.h>

@interface PerHeaderView()

@property (nonatomic, strong) UIImageView *backView;
@property (nonatomic, strong) UIButton *addressBtn;
@property (nonatomic, strong) UIButton *iconBtn;
@property (nonatomic, strong) UIView *lineView;
@property (nonatomic, strong) UILabel *descLabel;

@end

@implementation PerHeaderView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.backView];
        [self addSubview:self.addressBtn];
        [self addSubview:self.iconBtn];
        [self addSubview:self.lineView];
        [self addSubview:self.descLabel];

    }
    return self;
}

- (UIImageView *)backView {
    if (!_backView) {
        _backView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"per_back"]];
     }
    return _backView;
}

- (UIButton *)addressBtn {
    if (!_addressBtn) {
        _addressBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_addressBtn setBackgroundImage:[UIImage imageNamed:@"per_address_normal"] forState:UIControlStateNormal];
        [_addressBtn setBackgroundImage:[UIImage imageNamed:@"per_address_selected"] forState:UIControlStateSelected];

    }
    return _addressBtn;
}

- (UIButton *)iconBtn {
    if (!_iconBtn) {
        _iconBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_iconBtn setBackgroundImage:[UIImage imageNamed:@"per_icon"] forState:UIControlStateNormal];
        _iconBtn.layer.masksToBounds = YES;
        _iconBtn.layer.cornerRadius = 40.0;
        _iconBtn.layer.borderWidth = 2.0;
        _iconBtn.layer.borderColor = RGB(253, 213, 47).CGColor;
        
    }
    return _iconBtn;
}

- (UIView *)lineView {
    if (!_lineView) {
        _lineView = [[UIView alloc] init];
        [_lineView setBackgroundColor:RGB(253, 213, 47)];
    }
    return _lineView;
}

- (UILabel *)descLabel {
    if (!_descLabel) {
        _descLabel = [[UILabel alloc] init];
        _descLabel.text = @"北京分拨中心";
        _descLabel.textColor = RGB(255, 255, 255);
        _descLabel.textAlignment = NSTextAlignmentCenter;
        _descLabel.font = [UIFont systemFontOfSize:16.0];

    }
    return _descLabel;
}


- (void)layoutSubviews {
    WS(ws);
    [_backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(ws.mas_left);
        make.right.equalTo(ws.mas_right);
        make.top.equalTo(ws.mas_top);
        make.bottom.equalTo(ws.mas_bottom);
    }];
    
    [_addressBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(ws.mas_top).offset(35);
        make.right.equalTo(ws.mas_right).offset(-17);
        make.size.equalTo(CGSizeMake(12, 16));
    }];
    
    [_iconBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(ws.mas_top).offset(70);
        make.centerX.equalTo(ws.mas_centerX);
        make.size.equalTo(CGSizeMake(80, 80));
    }];
    
    [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(ws.iconBtn.mas_bottom).offset(18);
        make.centerX.equalTo(ws.mas_centerX);
        make.size.equalTo(CGSizeMake(55, 1));
    }];
    
    [_descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(ws.mas_left);
        make.right.equalTo(ws.mas_right);
        make.top.equalTo(ws.lineView.mas_bottom).offset(17);
        make.height.equalTo(16.0);
    }];
}




@end
